using AutoMapper;
using B.S.Data.MES.API.Applications.BaseData.Command.ProductMaterialCommand;
using B.S.Domain.BasicData.MaterialManagement.Product_material;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.BaseData.CommandHandlers.ProductMaterialCommandHandlers
{
    public class UpdateProductMaterialCommandHandler : IRequestHandler<UpdateProductMaterialCommand, APIRequst<int>>
    {
        private readonly IBaseRepository<Product_material> _productMaterialRepository;
        private readonly IMapper _mapper;

        public UpdateProductMaterialCommandHandler(IBaseRepository<Product_material> productMaterialRepository, IMapper mapper)
        {
            _productMaterialRepository = productMaterialRepository;
            _mapper = mapper;
        }

        public async Task<APIRequst<int>> Handle(UpdateProductMaterialCommand request, CancellationToken cancellationToken)
        {

            var su=    _mapper.Map<Product_material>(request);
            su.UpdateTime = DateTime.Now;
            su.CreateTime = DateTime.Now;
            await _productMaterialRepository.Update(su);
            return new APIRequst<int>
            {
                Code = RequstCode.成功,
                Msg = RequstCode.成功.ToString()
            };
        }
    }
}